"""
内置高阶函数
"""

class Employee:
    def __init__(self, eid, did, name, money):
        self.eid = eid  # 员工编号
        self.did = did  # 部门编号
        self.name = name
        self.money = money

    def __repr__(self):
        return f'Employee({self.eid}, {self.did}, {self.name}, {self.money})'



list_employees = [
    Employee(1001, 9002, "师父", 60000),
    Employee(1002, 9001, "孙悟空", 50000),
    Employee(1003, 9002, "猪八戒", 20000),
    Employee(1004, 9001, "沙僧", 30000),
    Employee(1005, 9001, "小白龙", 15000),
]

# 求工资最高的员工信息
emp1 = max(list_employees, key=lambda emp: emp.money)
print(emp1)

# 求工资最低的员工信息
emp2 = min(list_employees, key=lambda emp: emp.money)
print(emp2)

print('='* 30)
# 查询部门是9002的员工
for item in  filter(lambda emp:emp.did == 9002,list_employees):
    print(item)

# 查询所有员工的姓名
for name in map(lambda emp:emp.name,list_employees):
    print(name)

print('=' * 30)

# 按照工资升序排序
for emp in  sorted(list_employees, key=lambda emp: emp.money):
    print(emp)

print('=' * 30)

# 按照工资降序排序
for emp in  sorted(list_employees, key=lambda emp: emp.money,reverse=True):
    print(emp)
